﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LimpaGaragem.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        #region EVENTS

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnEnter_Click(object sender, EventArgs e)
        {
            ValidateLogin();
        }
        protected void btnSignout_Click(object sender, EventArgs e)
        {
            ValidateSignout();
        }
        
        #endregion

        #region METHODS

        private void ValidateLogin()
        {
            try
            {
                string strUserLogin = txtLoginBox.Text.Trim();
                string strUserPassword = txtPasswordBox.Text.Trim();
                if (strUserLogin == "edu.ohyama" && strUserPassword == "1234")
                {
                    LimpaGaragem.Model.User.Info objUserInfo = new LimpaGaragem.Model.User.Info();
                    objUserInfo.ID = 1;
                    objUserInfo.Name = "Eduardo Ohyama";
                    objUserInfo.Login = "edu.ohyama";
                    Session["UserLogged"] = objUserInfo;

                    ltrUserLogin.Text = objUserInfo.Name;
                    phUserLogin.Visible = false;
                    phUserLogged.Visible = true;

                    ((LimpaGaragem.Web.MasterPages.Default)this.Master).ValidateSessionUser();
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "window.alert(\"Usuário e/ou senha inválido(s)!\");", true);
                }
            }
            catch (Exception ex)
            {
                //
            }
        }
        private void ValidateSignout()
        {
            try
            {
                if (Session["UserLogged"] != null)
                {
                    Session.Remove("UserLogged");
                }
                phUserLogin.Visible = true;
                phUserLogged.Visible = false;
                ((LimpaGaragem.Web.MasterPages.Default)this.Master).ValidateSessionUser();
            }
            catch (Exception ex)
            {
                //
            }
        }

        #endregion
    }
}
